<?php
namespace wogu2\mvc\router;

use wogu2\stdlib\RequestInterface as RequestInterface;

class RouterStack implements RouterStackInterface
{
    private $_config = null;
    private $_routers = array();
    
    public function setConfig($config) {
        $this->_config = $config;
        if(!empty($config['routers'])) {
            foreach($config['routers'] as $routerName) {
                $this->addRouter(new $routerName);
            }
        }
    }

    public function addRouter(RouterInterface $router) {
        $this->_routers[] = $router;
    }
    
    public function match(RequestInterface $request) {
        foreach($this->_routers as $router) {
            if($router->match($request)) {
                return true;
            }
        }
        
        return false;
    }
}